<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

function admin_url() {
	return base_url() . "admin/";
}

function category_url($catCode, $page = 0, $ordering = '') {
	$url = '';
	if (!$catCode)
		$url = '';
	else if ($page > 1)
		$url = $catCode . "/trang-" . $page . ".html";
	else
		$url = $catCode . ".html";
	if ($ordering == 'topview') {
		$url = 'choi-nhieu/' . $url;
	}
	$url = base_url() . $url;
	return $url;
}

function event_url($event_id,$even_code) {
	$url = base_url() .'su-kien/'.$even_code.'-'.$event_id . ".html";
	return $url;
}
function post_url($post_id, $post_code = '') {
    $url = base_url() .$post_code.'-'.$post_id . ".html";
	return $url;
}

function user_url($action = '', $param = ''){
	$map = array(
		'index' => 'thong-tin-ca-nhan',
		'info' => 'thanh-vien',
		'favorites' => 'game-yeu-thich',
		'logout' => 'dang-xuat',
		'login' => 'dang-nhap',
		'lostpassword' => 'quen-mat-khau',
	);
	$url = base_url();
	if (in_array($action, array_keys($map))) {
		$url .= $map[$action];
	}else {
		$url .= 'user/'.$action;
	}
	if ($param) $url.= '/'.strtolower($param);
	if ($url) $url.='.html';
	return $url;
}

function image_src($patch = '',$name = '',$subserver = '') {
	if (strpos($patch, 'ttp://') || strpos($patch, 'ttps://'))
		return $patch;
	if($name != '')
		return image_src_cache($patch,$width,$height);
	if($subserver!='' && in_array($subserver, array('cdn1')) && $patch != '')
	{
		return prep_url($subserver.'.localhost/saovui/').$patch;
	}
	return base_url() . $patch;
}
$_ci = null;
function image_thumbnail($patch = '',$name = '') {
	if (strpos($patch, 'ttp://') || strpos($patch, 'ttps://'))
		return $patch;
	$patch = str_replace("images/","image/",$patch);
	global $_ci;
	if($_ci == null) {
		$_ci = &get_instance();
		$_ci->config->load('mimage');
	}
	$image_size = $_ci->config->item('IMAGE_SIZE');
	$width = 60;
	$height = 60;
	if(isset($image_size[$name])){
		$width = $image_size[$name][0];
		$height = $image_size[$name][1];
	}
	$patch = str_replace(basename($patch),$width."x".$height.'-'.basename($patch),$patch);
	return prep_url('cdn1.sao.vui.us/') . $patch;
}
function page404() {
	return base_url() . '404.html';
}

function theme_url($uri = '') {
	return base_url() . 'template/svtmpl/' . $uri;
}

function prd() {
	echo "<pre style='clear: both; border-top: 1px solid red;'>";
	if (func_get_args()) foreach (func_get_args() as $item) {
		print_r($item);
		echo "<hr />";
	}
	
	$bt = debug_backtrace();
	$caller = array_shift($bt);
	echo "<div style='color:red' >Call from line <strong>".$caller['line'] . "</strong> file " . $caller['file'] ."</div>";
	echo "</pre>";
	die();
}

